<?php
/**
 *     
 *   生成公钥私钥
 */
    function create_key($config) {  
        $res = openssl_pkey_new($config); 
        if($res == false) return false;  
        openssl_pkey_export($res, $private_key,null,$config);  
        $public_key = openssl_pkey_get_details($res);  
        return array('public_key'=>$public_key["key"],'private_key'=>$private_key);  
    } 
	
	$config = array(
        "config" => '/etc/pki/tls/openssl.cnf',
        "digest_alg" => "sha1",
        "private_key_bits" => 1024,
        "private_key_type" => OPENSSL_KEYTYPE_RSA,
        );
		
   
	$arr = create_key($config);

    if(!empty($arr)){
		file_put_contents('private_key.txt', $arr['private_key']);  
		file_put_contents('public_key.txt', $arr['public_key']);
        echo 'create key success!!';		
	}else{
		echo 'create key fail!!';
	}
?>
